/**
 *
 * 关卡一
 * @author 
 *
 */
class Guanka01 extends GuankaBase{
    /**怪物行走路径点*/
    private roadArr1: number[][];
    private roadArr2: number[][];
    protected friendHome:egret.Bitmap;
    protected enemyHome: egret.Bitmap;
    

    
    /**引用的层*/
    protected contentLayer: egret.Sprite;
    
    /**构造函数*/
	public constructor() {
        super();
        this.mtime = 0;
        
        //背景地图+网格信息
        this.bm.texture = RES.getRes("map0");
        this.bm.anchorOffsetX =this.bm.width/2;
        this.bm.anchorOffsetY = this.bm.height / 2;
        this.bm.x = GameSetting.swid / 2;
        this.bm.y = GameSetting.shei / 2;
        
        //地基位置数组、士兵集结点数组  
        this.leftPoseArr = [[120,160],[80,160],[160,160],[100,160],[140,160],[120,140],[80,140],[160,140],[100,140],[140,140]];
        this.rightPoseArr = [[360,160],[320,160],[400,160],[340,160],[380,160],[360,140],[320,140],[400,140],[340,140],[380,140]];
        //所有波敌人数据 （类型、数量、生命、速度、攻击力、价值）
        //1：范围伤害；2：攻击增强；3：反伤；4：平摊伤害；5：百分比伤害；6：重伤；7：被攻击回血；8：致盲；9：自爆；10：狂暴；11：闪避；12：范围法术
        this.enemyData = [
            [
                { "type": "Monster02","count": 10,"price": 6,"life": 70,"maxSpeed": 0.6,"damage": 40,"fireDelay": 500,"suckBlood": 0,"specialType": 0,"value": 1,"attackType": 1,"info": "狼群","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster05","count": 3,"price": 20,"life": 200,"maxSpeed": 0.9,"damage": 100,"fireDelay": 1500,"suckBlood": 0,"specialType": 0,"value": 1,"attackType": 1,"info": "三人一组的单挑王","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster02","count": 10,"price": 10,"life": 85,"maxSpeed": 0.6,"damage": 55,"fireDelay": 500,"suckBlood": 0,"specialType": 0,"value": 1,"attackType": 1,"info": "狼群","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster06","count": 3,"price": 10,"life": 200,"maxSpeed": 0.6,"damage": 100,"fireDelay": 600,"suckBlood": 0.5,"specialType": 0,"value": 1,"attackType": 1,"info": "吸血：将伤害的50%转化为生命值","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster13","count": 5,"price": 10,"life": 150,"maxSpeed": 0.6,"damage": 150,"fireDelay": 500,"suckBlood": 0,"specialType": 9,"value": 1,"attackType": 1,"info": "死后溅射毒液，对周围敌人造成等同攻击力的伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster05","count": 3,"price": 10,"life": 367,"maxSpeed": 0.6,"damage": 167,"fireDelay": 1500,"suckBlood": 0,"specialType": 0,"value": 1,"attackType": 1,"info": "三人一组的单挑王","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster06","count": 3,"price": 10,"life": 250,"maxSpeed": 0.6,"damage": 125,"fireDelay": 500,"suckBlood": 0.5,"specialType": 0,"value": 1,"attackType": 1,"info": "吸血：将伤害的50%转化为生命值","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster13","count": 5,"price": 10,"life": 180,"maxSpeed": 0.6,"damage": 180,"fireDelay": 500,"suckBlood": 0,"specialType": 9,"value": 1,"attackType": 1,"info": "死后溅射毒液，对周围敌人造成等同攻击力的伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster06","count": 3,"price": 10,"life": 300,"maxSpeed": 0.6,"damage": 150,"fireDelay": 500,"suckBlood": 0.5,"specialType": 0,"value": 1,"attackType": 1,"info": "吸血：将伤害的50%转化为生命值","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster07","count": 3,"price": 10,"life": 440,"maxSpeed": 0.6,"damage": 60,"fireDelay": 500,"suckBlood": 0,"specialType": 1,"value": 1,"attackType": 1,"info": "攻击对目标周围敌人造成同等伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster04","count": 3,"price": 10,"life": 800,"maxSpeed": 0.6,"damage": 60,"fireDelay": 500,"suckBlood": 0,"specialType": 10,"value": 1,"attackType": 1,"info": "每当一个同类死亡，提升100%攻击力和10%吸血。","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Boss01","count": 1,"price": 10,"life": 2000,"maxSpeed": 0.6,"damage": 140,"fireDelay": 1200,"suckBlood": 0,"specialType": 11,"value": 0.2,"attackType": 1,"info": "20%几率格挡攻击，并立即对攻击者反击","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Boss02","count": 1,"price": 10,"life": 2500,"maxSpeed": 0.6,"damage": 80,"fireDelay": 1000,"suckBlood": 0,"specialType": 2,"value": 1,"attackType": 1,"info": "每次攻击提升20%伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster12","count": 5,"price": 10,"life": 225,"maxSpeed": 0.6,"damage": 225,"fireDelay": 500,"suckBlood": 0,"specialType": 9,"value": 1,"attackType": 1,"info": "死后溅射毒液，对周围敌人造成等同攻击力的伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster07","count": 3,"price": 10,"life": 500,"maxSpeed": 0.6,"damage": 75,"fireDelay": 500,"suckBlood": 0,"specialType": 1,"value": 1,"attackType": 1,"info": "攻击对目标周围敌人造成同等伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Boss01","count": 1,"price": 10,"life": 2000,"maxSpeed": 0.6,"damage": 140,"fireDelay": 500,"suckBlood": 0,"specialType": 11,"value": 1,"attackType": 1,"info": "20%几率格挡攻击，并立即对攻击者反击","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Boss02","count": 1,"price": 10,"life": 2500,"maxSpeed": 0.6,"damage": 80,"fireDelay": 500,"suckBlood": 0,"specialType": 2,"value": 1,"attackType": 1,"info": "每次攻击提升20%伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster12","count": 5,"price": 10,"life": 225,"maxSpeed": 0.6,"damage": 225,"fireDelay": 500,"suckBlood": 0,"specialType": 9,"value": 1,"attackType": 1,"info": "死后溅射毒液，对周围敌人造成等同攻击力的伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ],[
                { "type": "Monster12","count": 5,"price": 10,"life": 225,"maxSpeed": 0.6,"damage": 225,"fireDelay": 500,"suckBlood": 0,"specialType": 9,"value": 1,"attackType": 1,"info": "死后溅射毒液，对周围敌人造成等同攻击力的伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster07","count": 3,"price": 10,"life": 550,"maxSpeed": 0.6,"damage": 75,"fireDelay": 500,"suckBlood": 0,"specialType": 1,"value": 1,"attackType": 1,"info": "攻击对目标周围敌人造成同等伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 },
                { "type": "Monster02","count": 10,"price": 10,"life": 2500,"maxSpeed": 0.6,"damage": 80,"fireDelay": 500,"suckBlood": 0,"specialType": 11,"value": 1,"attackType": 1,"info": "狼群","tip": "可升级为近卫","unitTip": "防御","min": 40 }
            ],[
                { "type": "b1","count": 1,"price": 10,"life": 2500,"maxSpeed": 0.6,"damage": 0,"fireDelay": 500,"suckBlood": 0,"specialType": 12,"value": 200,"attackType": 1,"info": "在附近所有敌人位置召唤一个火球，造成200范围伤害","tip": "可升级为近卫","unitTip": "防御","min": 50 }
            ]
        ];
        this.soldierArr = ["s01","s02","s03","s04","s05","s06","s07"]


        //创建地基
        //this.createBase();
        //创建双方主将
//        this.FriendLord = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.boss1 = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.boss2 = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.EnemyLord = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.boss3 = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.boss4 = <HumanTower>ObjectPool.getInstance().createObject(HumanTower);
//        this.build(this.FriendLord,"myLord",240,550,true);
//        this.build(this.boss1,"myTower",120,490,true);
//        this.build(this.boss2,"myTower",360,490,true);
//        this.build(this.EnemyLord,"enemyLord",240,70,false);
//        this.build(this.boss3,"enemyTower",120,120,false);
//        this.build(this.boss4,"enemyTower",360,120,false);
        this.enemyHome = new egret.Bitmap;
        this.enemyHome = Utils.createBitmapByName("life_png");
        this.baseLayer.addChild(this.enemyHome);
        this.enemyHome.anchorOffsetX = this.enemyHome.width / 2;
        this.enemyHome.x =  240;
        this.enemyHome.y =  40;
        this.friendHome = new egret.Bitmap;
        this.friendHome = Utils.createBitmapByName("life_png");
        this.baseLayer.addChild(this.friendHome);
        this.friendHome.anchorOffsetX = this.friendHome.width / 2;
        this.friendHome.x = 240;
        this.friendHome.y = 530;
        
        //创造UI
        this.createUI();
        //初始化
        this.init();
        
	}
	
	
    /**初始化各种数据*/
    public init(){
        this.atime = 0;
        //初始化各种计算变量
        this.hard = 1;

        this.curBo = 4;
        this.otime = 0;
        this.boing = false;
        this.EnemyLife = 500;
        this.EnemyLife = 500;
        //开局金币、剩余生命、波数
        this.gold = 150;
        this.income = 1;
        this.guankaUI.setGold(this.gold);


        
        //背景音乐
        SoundManager.playBgSound("map0bg");
        //心跳控制器启动
        egret.Ticker.getInstance().register(this.onEnterFrame,this);
    }
    
    /**实时刷新*/
    protected onEnterFrame(advancedTime: number) {
        super.onEnterFrame(advancedTime);
    }

    
    /**再次尝试*/
    protected tryAgainHandle(e: MainEvent) {
        var i: number;
        //清除所有对象
        while(this.objLayer.numChildren>0){
            this.objLayer.removeChildAt(0);
        }
        //清除工具
        while(this.toolLayer.numChildren>0){
            this.toolLayer.removeChildAt(0);
        }
        //数组清零
        this.towerArr = [];
        this.objArr = [];
        this.enemy = [];
        this.soldier = [];
        this.buildQuene = [];
        //初始化各种数据
        this.init();
    }
    
	/**销毁关卡*/
	public destroy(){
        super.destroy();
        RES.destroyRes(GuanKaConfig.guankaData[Main.curIdx]);
        
        this.roadArr1 = null;
        this.roadArr2 = null;
        
        //取消心跳控制器
        //egret.Ticker.getInstance().unregister(this.onEnterFrame,this);
	}
}
